home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / awt / Desktop.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  3.8 KB  |  167 lines

  1. package java.awt;
  2.  
  3. import java.awt.peer.DesktopPeer;
  4. import java.io.File;
  5. import java.io.FilePermission;
  6. import java.io.IOException;
  7. import java.net.MalformedURLException;
  8. import java.net.URI;
  9. import java.net.URISyntaxException;
  10. import sun.awt.AppContext;
  11. import sun.awt.DesktopBrowse;
  12. import sun.awt.SunToolkit;
  13.  
  14. public class Desktop {
  15.    private DesktopPeer peer = Toolkit.getDefaultToolkit().createDesktopPeer(this);
  16.  
  17.    private Desktop() {
  18.    }
  19.  
  20.    public static synchronized Desktop getDesktop() {
  21.       if (GraphicsEnvironment.isHeadless()) {
  22.          throw new HeadlessException();
  23.       } else if (!isDesktopSupported()) {
  24.          throw new UnsupportedOperationException("Desktop API is not supported on the current platform");
  25.       } else {
  26.          AppContext var0 = AppContext.getAppContext();
  27.          Desktop var1 = (Desktop)var0.get(Desktop.class);
  28.          if (var1 == null) {
  29.             var1 = new Desktop();
  30.             var0.put(Desktop.class, var1);
  31.          }
  32.  
  33.          return var1;
  34.       }
  35.    }
  36.  
  37.    public static boolean isDesktopSupported() {
  38.       Toolkit var0 = Toolkit.getDefaultToolkit();
  39.       return var0 instanceof SunToolkit ? ((SunToolkit)var0).isDesktopSupported() : false;
  40.    }
  41.  
  42.    public boolean isSupported(Action var1) {
  43.       return this.peer.isSupported(var1);
  44.    }
  45.  
  46.    private static void checkFileValidation(File var0) {
  47.       if (var0 == null) {
  48.          throw new NullPointerException("File must not be null");
  49.       } else if (!var0.exists()) {
  50.          throw new IllegalArgumentException("The file: " + var0.getPath() + " doesn't exist.");
  51.       } else {
  52.          var0.canRead();
  53.       }
  54.    }
  55.  
  56.    private void checkActionSupport(Action var1) {
  57.       if (!this.isSupported(var1)) {
  58.          throw new UnsupportedOperationException("The " + var1.name() + " action is not supported on the current platform!");
  59.       }
  60.    }
  61.  
  62.    private void checkAWTPermission() {
  63.       SecurityManager var1 = System.getSecurityManager();
  64.       if (var1 != null) {
  65.          var1.checkPermission(new AWTPermission("showWindowWithoutWarningBanner"));
  66.       }
  67.  
  68.    }
  69.  
  70.    public void open(File var1) throws IOException {
  71.       this.checkAWTPermission();
  72.       this.checkExec();
  73.       this.checkActionSupport(java.awt.Desktop.Action.OPEN);
  74.       checkFileValidation(var1);
  75.       this.peer.open(var1);
  76.    }
  77.  
  78.    public void edit(File var1) throws IOException {
  79.       this.checkAWTPermission();
  80.       this.checkExec();
  81.       this.checkActionSupport(java.awt.Desktop.Action.EDIT);
  82.       var1.canWrite();
  83.       checkFileValidation(var1);
  84.       this.peer.edit(var1);
  85.    }
  86.  
  87.    public void print(File var1) throws IOException {
  88.       this.checkExec();
  89.       SecurityManager var2 = System.getSecurityManager();
  90.       if (var2 != null) {
  91.          var2.checkPrintJobAccess();
  92.       }
  93.  
  94.       this.checkActionSupport(java.awt.Desktop.Action.PRINT);
  95.       checkFileValidation(var1);
  96.       this.peer.print(var1);
  97.    }
  98.  
  99.    public void browse(URI var1) throws IOException {
  100.       SecurityException var2 = null;
  101.  
  102.       try {
  103.          this.checkAWTPermission();
  104.          this.checkExec();
  105.       } catch (SecurityException var6) {
  106.          var2 = var6;
  107.       }
  108.  
  109.       this.checkActionSupport(java.awt.Desktop.Action.BROWSE);
  110.       if (var1 == null) {
  111.          throw new NullPointerException();
  112.       } else if (var2 == null) {
  113.          this.peer.browse(var1);
  114.       } else {
  115.          Object var3 = null;
  116.  
  117.          try {
  118.             var7 = var1.toURL();
  119.          } catch (MalformedURLException var5) {
  120.             throw new IllegalArgumentException("Unable to convert URI to URL", var5);
  121.          }
  122.  
  123.          DesktopBrowse var4 = DesktopBrowse.getInstance();
  124.          if (var4 == null) {
  125.             throw var2;
  126.          } else {
  127.             var4.browse(var7);
  128.          }
  129.       }
  130.    }
  131.  
  132.    public void mail() throws IOException {
  133.       this.checkAWTPermission();
  134.       this.checkExec();
  135.       this.checkActionSupport(java.awt.Desktop.Action.MAIL);
  136.       Object var1 = null;
  137.  
  138.       try {
  139.          URI var4 = new URI("mailto:?");
  140.          this.peer.mail(var4);
  141.       } catch (URISyntaxException var3) {
  142.       }
  143.  
  144.    }
  145.  
  146.    public void mail(URI var1) throws IOException {
  147.       this.checkAWTPermission();
  148.       this.checkExec();
  149.       this.checkActionSupport(java.awt.Desktop.Action.MAIL);
  150.       if (var1 == null) {
  151.          throw new NullPointerException();
  152.       } else if (!"mailto".equalsIgnoreCase(var1.getScheme())) {
  153.          throw new IllegalArgumentException("URI scheme is not \"mailto\"");
  154.       } else {
  155.          this.peer.mail(var1);
  156.       }
  157.    }
  158.  
  159.    private void checkExec() throws SecurityException {
  160.       SecurityManager var1 = System.getSecurityManager();
  161.       if (var1 != null) {
  162.          var1.checkPermission(new FilePermission("<<ALL FILES>>", "execute"));
  163.       }
  164.  
  165.    }
  166. }
  167.